package cn.net.csit.platform_cloud.basicmodel.service.impl;

import cn.net.csit.platform_cloud.basicmodel.domain.BasicPropertyGroupDomain;
import cn.net.csit.platform_cloud.basicmodel.domain.BasicPropertyGroupDomainExample;
import cn.net.csit.platform_cloud.basicmodel.mapper.BasicPropertyGroupDomainMapper;
import cn.net.csit.platform_cloud.basicmodel.service.IBackupDataService;
import cn.net.csit.platform_cloud.basicmodel.service.IBasicPropertyGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName:
 * @Author:yanwenjuan
 * @Date:2019/4/217:20
 * @Description:
 */
@Service
public class BasicPropertyGroupServiceImpl implements IBasicPropertyGroupService {
    @Autowired
    private BasicPropertyGroupDomainMapper mapper;
    @Autowired
    IBackupDataService backupDataService;



    @Override
    public int insert(BasicPropertyGroupDomain record) {
        return mapper.insert(record);
    }

    @Override
    public List<BasicPropertyGroupDomain> getAll() {
        BasicPropertyGroupDomainExample example=new BasicPropertyGroupDomainExample();
        BasicPropertyGroupDomainExample.Criteria criteria= example.createCriteria();
        criteria.andUuidIsNotNull();
        return mapper.selectByExample(example);
    }

    @Override
    public List<BasicPropertyGroupDomain> getAll(Map<String, String> map) {
        BasicPropertyGroupDomainExample example=new BasicPropertyGroupDomainExample();
        BasicPropertyGroupDomainExample.Criteria criteria= example.createCriteria();
        criteria.andUuidIsNotNull();
        if(null!=map.get("propGroupName")){
            criteria.andPropGroupNameEqualTo(map.get("propGroupName"));
        }
        return mapper.selectByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(String uuid) {
        return mapper.deleteByPrimaryKey(uuid);
    }

    @Override
    public BasicPropertyGroupDomain selectByPrimaryKey(String uuid) {
        return mapper.selectByPrimaryKey(uuid);
    }

    @Override
    public int updateByPrimaryKey(BasicPropertyGroupDomain record) {
        return mapper.updateByPrimaryKey(record);
    }

    @Override
    public Map<String, String> getAllByGN(Map<String, String> map) {
        Map<String,String> result = new HashMap<>();
        String where = "where 1 = 1";
        if(null!=map&null!=map.get("prop_group_name")){
            where =where+" and prop_group_name='"+map.get("prop_group_name")+"'";
        }
        StringBuilder sb=new StringBuilder();
        sb.append(" SELECT *");
        sb.append(" FROM basic_property_group");
        sb.append(" "+where);
        result=backupDataService.customQueryItem(sb).get(0);
        return result;
    }

    @Override
    public List<Map<String, String>> getAllMap() {
        List<Map<String, String>> result = new ArrayList<>();
        StringBuilder sb=new StringBuilder();
        sb.append(" SELECT uuid,prop_group_name");
        sb.append(" FROM basic_property_group  ");
        result=backupDataService.customQueryItem(sb);
        return result;
    }


}
